package db

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"time"
)

var Db *gorm.DB

func InitDB() (err error) {
	Db, err = gorm.Open("mysql", "root:mysql@(127.0.0.1:3306)/gorm?charset=utf8mb4&parseTime=True&loc=Local")
	if err != nil {
		fmt.Println("gorm.Open error:", err)
	}
	Db.DB().SetMaxIdleConns(10)  //设置最大空闲树
	Db.DB().SetMaxOpenConns(100)  //设置最大连接数
	Db.DB().SetConnMaxLifetime(5*time.Second)
	return
}
